package com.yawn.demomybatis.dao;

import com.yawn.demomybatis.entity.Person;
import com.yawn.demomybatis.entity.School;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PersonDao2 {

    @Select("select * from person where id=#{id}")
//    @ResultType(Person.class)
    @ResultMap("personMap")
    Person get(@Param("id") String id);

    @Select("select * from person")
    @Results(id = "personMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "nickName", column = "name"),
            @Result(property = "age", column = "age"),
            @Result(
                    property = "school", column = "schoolId",
                    one = @One(
                            fetchType = FetchType.EAGER,
//                            fetchType = FetchType.LAZY,
//                            fetchType = FetchType.DEFAULT,
                            select = "com.yawn.demomybatis.dao.SchoolDao.get"
                    )
            )
    })
    List<Person> list();

}
